Let me see if I can explain it to you in simple terms Crabby.
In any population of animals of a particular species you have a variation in traits. That variation in traits is a reflection of variation in DNA. One such variation in traits would be preference for the taste of pus. Some in the population would love the taste of pus and others won't.
Those that love the taste of pus would lick the pus laden wounds, disinfecting it and halting the progression of infection. The incidence of death by infection would thus be lower in this set of animals. They would thus have a longer lifespan per capita and more opportunity to reproduce.
Those that don't love the taste of pus would not lick the pus laden wounds, and would thus have more deaths by infection. The incidence of death by infection would thus be higher in this set of animals. They would thus have a shorter lifespan per capita and less opportunity to reproduce.
So over time, because the pus lovers have a reproductive advantage - due to their infection survival advantage - the offspring of the pus lovers will outnumber the offspring of the pus haters (or pus "apathites"). Eventually over the course of many generations the genes that result in the love of pus will pervade the whole population. Fast forward millions of years and we arrive at today where dogs virtually all love to lick pus wounds. It's not because they remember the taste of pus from their genes. It's because the genes for loving the taste of pus were naturally selected for because it afforded the species a survival advantage. It has nothing to do with memory of what pus tastes like. The dogs just find the smell and taste pleasing without knowing how or why.
So let's review: There's variation in genetic traits in every population. Those genetic traits that happen to ultimately provide a reproductive advantage within the environment of the population, will eventually become the dominant trait in the population. This is called natural selection. The environment acts as a seive, selecting for survival, those traits that are most advantageous to the animal in that environment. There's no intelligence involved. It's all probability and statistics.